//
//  ExaminaColumnReasonView.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/23.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "ExaminaColumnReasonView.h"
@interface ExaminaColumnReasonView()
@property (nonatomic,strong) UIView *headerView;
@property (nonatomic,strong) UIView *footerView;
@property (nonatomic,strong) UIView *shadowView;
@property (nonatomic,strong) UITextView *contentTextView;
@property (nonatomic,strong) UIView *backView;
@end

@implementation ExaminaColumnReasonView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    [self addSubview:self.shadowView];
}

#pragma mark ==========懒加载==========
- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 525*SCALEUNIT, 475*SCALEUNIT)];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.center = self.center;
        [_backView addSubview:self.headerView];
        [_backView addSubview:self.contentTextView];
        [_backView addSubview:self.footerView];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 525*SCALEUNIT, 470*SCALEUNIT) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(15*SCALEUNIT,15*SCALEUNIT)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = CGRectMake(0, 0, 525*SCALEUNIT, 470*SCALEUNIT);
        maskLayer.path = maskPath.CGPath;
        _backView.layer.mask = maskLayer;
    }
    return _backView;
}
- (UITextView *)contentTextView{//525*475
    
    if (!_contentTextView) {
        _contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(20*SCALEUNIT, CGRectGetMaxY(self.headerView.frame), 485*SCALEUNIT, 200*SCALEUNIT)];
    }
    return _contentTextView;
}
- (UIView *)shadowView{
    if (!_shadowView) {
        _shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, -CGRectGetHeight(self.frame), CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];
        _shadowView.backgroundColor = RGBA(25, 25, 25, 0.5);
    }
    return _shadowView;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView.backgroundColor = [UIColor whiteColor];
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 525*SCALEUNIT, 140*SCALEUNIT)];
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_headerView.frame), 90*SCALEUNIT)];
        title.text = @"拒绝原因";
        title.textAlignment = NSTextAlignmentCenter;
        title.font = [UIFont systemFontOfSize:LoginFont-1];
        title.textColor = [UIColor colorWithHexString:@"#282828"];
        [_headerView addSubview:title];
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame), CGRectGetWidth(_headerView.frame), SCALEUNIT)];
        line.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
        [_headerView addSubview:line];
    }
    return _headerView;
}
- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.contentTextView.frame), 525*SCALEUNIT, 135*SCALEUNIT)];
        UIButton *sure = [self returnButtonWithTitleColor:[UIColor whiteColor] WithBackgroundColor:[UIColor colorWithHexString:@"#21d4a4"] WithTitle:@"确定" WithjudgeNum:1];
        [sure addTarget:self action:@selector(actionChange:) forControlEvents:UIControlEventTouchUpInside];
        sure.tag = 10001;
        [_footerView addSubview:sure];
        
        UIButton *cancle = [self returnButtonWithTitleColor:[UIColor colorWithHexString:@"#21d4a4"] WithBackgroundColor:[UIColor whiteColor] WithTitle:@"取消" WithjudgeNum:2];
        cancle.tag = 10000;
        [cancle addTarget:self action:@selector(actionChange:) forControlEvents:UIControlEventTouchUpInside];
        [_footerView addSubview:cancle];
    }
    return _footerView;
}

- (UIButton *)returnButtonWithTitleColor:(UIColor *)titleColor WithBackgroundColor:(UIColor *)backColor WithTitle:(NSString *)title WithjudgeNum:(NSInteger)judgeNum{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(judgeNum==1?0:CGRectGetWidth(_headerView.frame)/2.0, 45*SCALEUNIT, CGRectGetWidth(_headerView.frame)/2.0, 90*SCALEUNIT);
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:LoginFont-3]];
    [btn setBackgroundColor:backColor];
    return btn;
}

#pragma mark ==========actionChange==========
- (void)actionChange:(UIButton *)btn{
    [self endAnimation];
    if ([self.delegate respondsToSelector:@selector(trainManageSelectViewDelegateWithReason:WithState:)]) {
        [self.delegate trainManageSelectViewDelegateWithReason:self.contentTextView.text WithState:btn.tag-10000];
    }
}

#pragma mark ==========开启+结束动画动画==========
- (void)doAnimation{
    [UIView animateWithDuration:0.7f animations:^{
        self.shadowView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(self.frame));
    } completion:^(BOOL finished) {
        [self addSubview:self.backView];
    }];
}
- (void)endAnimation{
    [self.backView removeFromSuperview];
    [UIView animateWithDuration:0.7f animations:^{
        self.shadowView.transform = CGAffineTransformMakeTranslation(0, -CGRectGetHeight(self.frame));
    }];
}



@end
